home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mint110s / proc.h < prev    next >
C/C++ Source or Header  |  1994-02-09  |  9KB  |  248 lines

  1. /*
  2. Copyright 1990,1991,1992 Eric R. Smith.
  3. Copyright 1992,1993,1994 Atari Corporation.
  4. All rights reserved.
  5. */
  6.  
  7. /* proc.h: defines for various process related things */
  8. #ifndef _proc_h
  9. #define _proc_h
  10.  
  11. #include "file.h"
  12.  
  13. /* a process context consists, for now, of its registers */
  14.  
  15. typedef struct _context {
  16.     long    regs[15];    /* registers d0-d7, a0-a6 */
  17.     long    usp;        /* user stack pointer (a7) */
  18.     short    sr;        /* status register */
  19.     long    pc;        /* program counter */
  20.     long    ssp;        /* supervisor stack pointer */
  21.     long    term_vec;    /* GEMDOS terminate vector (0x102) */
  22. /*
  23.  * AGK: if running on a TT and the user is playing with the FPU then we
  24.  * must save and restore the context. We should also consider this for
  25.  * I/O based co-processors, although this may be difficult due to
  26.  * possibility of a context switch in the middle of an I/O handshaking
  27.  * exchange.
  28.  */
  29.     unsigned char    fstate[216];    /* FPU internal state */
  30.     long    fregs[3*8];    /* registers fp0-fp7 */
  31.     long    fctrl[3];    /* FPCR/FPSR/FPIAR */
  32.     char    ptrace;        /* trace exception is pending */
  33.     char    pad1;        /* junk */
  34.     long    iar;        /* unused */
  35.     short    res[4];        /* unused, reserved */
  36. /*
  37.  * Saved CRP and TC values.  These are necessary for memory protection.
  38.  */
  39.  
  40.     crp_reg crp;            /* 64 bits */
  41.     tc_reg tc;            /* 32 bits */
  42. /*
  43.  * AGK: for long (time-wise) co-processor instructions (FMUL etc.), the
  44.  * FPU returns NULL, come-again with interrupts allowed primitives. It
  45.  * is highly likely that a context switch will occur in one of these if
  46.  * running a mathematically intensive application, hence we must handle
  47.  * the mid-instruction interrupt stack. We do this by saving the extra
  48.  * 3 long words and the stack format word here.
  49.  */
  50.     unsigned short    sfmt;    /* stack frame format identifier */
  51.     short    internal[42];    /* internal state -- see framesizes[] for size */
  52. } CONTEXT;
  53.  
  54. #define PROC_CTXTS    2
  55. #define SYSCALL        0    /* saved context from system call    */
  56. #define CURRENT        1    /* current saved context        */
  57.  
  58. /*
  59.  * Timeout events are stored in a list; the "when" field in the event
  60.  * specifies the number of milliseconds *after* the last entry in the
  61.  * list that the timeout should occur, so routines that manipulate
  62.  * the list only need to check the first entry.
  63.  */
  64.  
  65. typedef struct timeout {
  66.     struct timeout *next;
  67.     struct proc    *proc;
  68.     long    when;
  69.     void    (*func) P_((struct proc *)); /* function to call at timeout */
  70. } TIMEOUT;
  71.  
  72. #ifndef GENMAGIC
  73. extern TIMEOUT *tlist;
  74. #endif
  75.  
  76. #define NUM_REGIONS    64    /* number of memory regions alloced at a time */
  77. #define MIN_HANDLE    (-5)    /* minimum handle number        */
  78. #define MIN_OPEN    6    /* 0..MIN_OPEN-1 are reserved for system */
  79. #define MAX_OPEN    32    /* max. number of open files for a proc    */
  80. #define SSTKSIZE    8000    /* size of supervisor stack (in bytes)     */
  81. #define ISTKSIZE    2000    /* size of interrupt stack (in bytes)    */
  82. #define STKSIZE        (ISTKSIZE + SSTKSIZE)
  83.  
  84. #define FRAME_MAGIC    0xf4a3e000UL
  85.                 /* magic for signal call stack */
  86. #define CTXT_MAGIC    0xabcdef98UL
  87. #define CTXT2_MAGIC    0x87654321UL
  88.                 /* magic #'s for contexts */
  89.  
  90. #define PNAMSIZ        8    /* no. of characters in a process name */
  91.  
  92. #define DOM_TOS        0    /* TOS process domain */
  93. #define DOM_MINT    1    /* MiNT process domain */
  94.  
  95. typedef struct proc {
  96.     long    sysstack;        /* must be first        */
  97.     CONTEXT    ctxt[PROC_CTXTS];    /* must be second        */
  98.  
  99. /* this is stuff that the public can know about */
  100.     long    magic;            /* validation for proc struct    */
  101.  
  102.     BASEPAGE *base;            /* process base page        */
  103.     short    pid, ppid, pgrp;
  104.     short    ruid;            /* process real user id     */
  105.     short    rgid;            /* process real group id     */
  106.     short    euid, egid;        /* effective user and group ids */
  107.  
  108.     ushort    memflags;        /* e.g. malloc from alternate ram */
  109.     short    pri;            /* base process priority     */
  110.     short    wait_q;            /* current process queue    */
  111.  
  112. /* note: wait_cond should be unique for each kind of condition we might
  113.  * want to wait for. Put a define below, or use an address in the
  114.  * kernel as the wait condition to ensure uniqueness.
  115.  */
  116.     long    wait_cond;        /* condition we're waiting on    */
  117.                     /* (also return code from wait) */
  118.  
  119. #define WAIT_MB        0x3a140001L    /* wait_cond for p_msg call    */
  120. #define WAIT_SEMA    0x3a140003L    /* wait_cond for p_semaphore    */
  121.  
  122.     /* (all times are in milliseconds) */
  123.     /* usrtime must always follow systime */
  124.     ulong    systime;        /* time spent in kernel        */
  125.     ulong    usrtime;        /* time spent out of kernel    */
  126.     ulong    chldstime;        /* children's kernel time     */
  127.     ulong    chldutime;        /* children's user time        */
  128.  
  129.     ulong    maxmem;            /* max. amount of memory to use */
  130.     ulong    maxdata;        /* max. data region for process */
  131.     ulong    maxcore;        /* max. core memory for process */
  132.     ulong    maxcpu;            /* max. cpu time to use     */
  133.  
  134.     short    domain;            /* process domain (TOS or UNIX)    */
  135.  
  136.     short    curpri;            /* current process priority    */
  137. #define MIN_NICE -20
  138. #define MAX_NICE 20
  139.  
  140. /* EVERYTHING BELOW THIS LINE IS SUBJECT TO CHANGE:
  141.  * programs should *not* try to read this stuff via the U:\PROC dir.
  142.  */
  143.  
  144.     /* jr: two fields to hold information passed to Pexec */
  145.     char    fname[PATH_MAX];    /* name of binary */
  146.     char    cmdlin[128];        /* original command line */
  147.  
  148.     char    name[PNAMSIZ+1];    /* process name            */
  149.     TIMEOUT    *alarmtim;        /* alarm() event        */
  150.     short    slices;            /* number of time slices before this
  151.                        process gets to run again */
  152.  
  153.     short    bconmap;        /* Bconmap mapping        */
  154.     FILEPTR *midiout;        /* MIDI output            */
  155.     FILEPTR *midiin;        /* MIDI input            */
  156.     FILEPTR    *prn;            /* printer            */
  157.     FILEPTR *aux;            /* auxiliary tty        */
  158.     FILEPTR    *control;        /* control tty            */
  159.     FILEPTR    *handle[MAX_OPEN];    /* file handles            */
  160.  
  161.     uchar    fdflags[MAX_OPEN];    /* file descriptor flags    */
  162.  
  163.     ushort    num_reg;        /* number of memory regions allocated */
  164.     MEMREGION **mem;        /* allocated memory regions    */
  165.     virtaddr *addr;            /* addresses of regions        */
  166.  
  167.     ulong    sigpending;        /* pending signals        */
  168.     ulong    sigmask;        /* signals that are masked    */
  169.     ulong    sighandle[NSIG];    /* signal handlers        */
  170.     ushort    sigflags[NSIG];        /* signal flags            */
  171.     ulong    sigextra[NSIG];        /* additional signals to be masked
  172.                        on delivery     */
  173.     ulong    nsigs;            /* number of signals delivered     */
  174.     char    *mb_ptr;        /* p_msg buffer ptr        */
  175.     long    mb_long1, mb_long2;    /* p_msg storage        */
  176.     long    mb_mbid;        /* p_msg id being waited for    */
  177.     short    mb_mode;        /* p_msg mode being waiting in    */
  178.     short    mb_writer;        /* p_msg pid of writer of msg    */
  179.  
  180.     short    curdrv;            /* current drive        */
  181.     ushort    umask;            /* file creation mask        */
  182.     fcookie root[NUM_DRIVES];    /* root directories        */
  183.     fcookie    curdir[NUM_DRIVES];    /* current directory        */
  184.  
  185.     long    usrdata;        /* user-supplied data        */
  186.  
  187.     DTABUF    *dta;            /* current DTA            */
  188. #define NUM_SEARCH    10        /* max. number of searches    */
  189.     DTABUF *srchdta[NUM_SEARCH];    /* for Fsfirst/next        */
  190.     DIR    srchdir[NUM_SEARCH];    /* for Fsfirst/next        */
  191.     long    srchtim[NUM_SEARCH];    /* for Fsfirst/next        */
  192.     
  193.     DIR    *searches;        /* open directory searches    */
  194.  
  195.     long    txtsize;        /* size of text region (for fork()) */
  196.  
  197.     long ARGS_ON_STACK (*criticerr) P_((long)); /* critical error handler    */
  198.     void    *logbase;        /* logical screen base        */
  199.  
  200.     struct proc *ptracer;        /* process which is tracing this one */
  201.     short    ptraceflags;        /* flags for process tracing */
  202.     short    starttime;        /* time and date when process    */
  203.     short    startdate;        /* was started            */
  204.  
  205.     short    in_dos;            /* flag: 1 = process is executing a GEMDOS call */
  206.  
  207.     void    *page_table;        /* rounded page table pointer    */
  208.     void    *pt_mem;        /* original kmalloc'd block for above */
  209.  
  210.     ulong    exception_pc;        /* pc at time of bombs        */
  211.     ulong    exception_ssp;        /* ssp at time of bomb (e.g. bus error)    */
  212.     ulong    exception_tbl;        /* table in use at exception time */
  213.     ulong    exception_addr;        /* access address from stack    */
  214.     ushort    exception_mmusr;    /* result from ptest insn    */
  215.  
  216.     short    fork_flag;        /* flag: set to 1 if process has called Pfork() */
  217.  
  218.     struct    proc *q_next;        /* next process on queue    */
  219.     struct     proc *gl_next;        /* next process in system    */
  220.     char    stack[STKSIZE+4];    /* stack for system calls    */
  221. } PROC;
  222.  
  223.  
  224. /* different process queues */
  225.  
  226. #define CURPROC_Q    0
  227. #define READY_Q        1
  228. #define WAIT_Q        2
  229. #define IO_Q        3
  230. #define ZOMBIE_Q    4
  231. #define TSR_Q        5
  232. #define STOP_Q        6
  233. #define SELECT_Q    7
  234.  
  235. #define NUM_QUEUES    8
  236.  
  237. #ifndef GENMAGIC
  238. extern PROC *proclist;            /* list of all active processes */
  239. extern PROC *curproc;            /* current process        */
  240. extern PROC *rootproc;            /* pid 0 -- MiNT itself        */
  241. extern PROC *sys_q[NUM_QUEUES];        /* process queues        */
  242.  
  243. extern long page_table_size;
  244.  
  245. #endif
  246.  
  247. #endif /* _proc_h */
  248.